<?php
include('config.php');

//holaaaa
if(isset($_GET['mas'])){
$cantidad = $_GET['mas'];
$ipUsuario=getIP(); 

$insertCantidad_sql = 'INSERT INTO vaquitaCervezaProject (cantidad,ipAdress) VALUES(' . $cantidad . ',' . $ipUsuario . ')';
$insertCantidad= mysql_query($insertCantidad_sql) or die(mysql_error());

$query = "SELECT SUM(cantidad) FROM  despensadm_com_ar_labs.vaquitaCervezaProject"; 
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
	$cantidad = $row['SUM(cantidad)'];
}
echo $cantidad;
} else { 
echo 'Error! Please fill all fileds!';
}

function getIP() {  
    if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {  
       $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];  
    }  
    elseif (isset($_SERVER['HTTP_VIA'])) {  
       $ip = $_SERVER['HTTP_VIA'];  
    }  
    elseif (isset($_SERVER['REMOTE_ADDR'])) {  
       $ip = $_SERVER['REMOTE_ADDR'];  
    }  
    else {  
       $ip = "unknown";  
    }  
     
    return "'$ip'";  
}  
?>